package com.Blili;

import org.hamcrest.core.Is;
import org.junit.Test;

import java.util.Stack;

/**
 * B站第二题
 */
public class test2 {
    /**
     *
     * @param s string字符串
     * @return bool布尔型
     */
    public boolean IsValidExp (String s) {
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i<s.length(); i++){
            char c = s.charAt(i);
            if(c == '(' || c == '{' || c == '['){
                stack.push(s.charAt(i));
            }else if(c == ')' && stack.size() > 0 && stack.peek() == '('){
                stack.pop();
            }else if(c == ']' && stack.size() > 0 && stack.peek() == '['){
                stack.pop();
            }else if(c == '}' && stack.size() > 0 && stack.peek() == '{'){
                stack.pop();
            }else{
                return false;
            }
        }
        return stack.size() == 0;
    }

    @Test
    public void test(){
        String str = "{[]}";
        System.out.println(IsValidExp(str));
    }
}
